package com.gzsxy.esjy.service.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzsxy.esjy.service.base.dto.response.ProductPicRsp;
import com.gzsxy.esjy.service.product.dao.ProductPicMapper;
import com.gzsxy.esjy.service.product.entity.ProductPic;
import com.gzsxy.esjy.service.product.service.ProductPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 商品图片
 * @date 2022/1/23 11:55
 */
@Service
public class ProductPicServiceImpl  extends ServiceImpl<ProductPicMapper, ProductPic> implements ProductPicService {


    @Autowired
    private ProductPicMapper productPicMapper;

    /**
     * @description: 根据商品id查询对应的图片
     * @param productId 商品id
     * @return
     */
    @Override
    public List<ProductPicRsp> getPicByProductId(String productId) {
        LambdaQueryWrapper<ProductPic> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProductPic::getProductId,productId);
        List<ProductPic> productPics = productPicMapper.selectList(wrapper);
        List<ProductPicRsp> list = JSON.parseArray(JSON.toJSONString(productPics), ProductPicRsp.class);
        return list;
    }
}
